package com.example.himalayaproject.subscription.activity;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.himalayaproject.R;
import com.example.himalayaproject.adapter.FindViewpagerAdapter;
import com.example.himalayaproject.subscription.fragment.SpecialDetailsFragment;
import com.example.himalayaproject.subscription.fragment.SpecialProgramFragment;
import com.example.himalayaproject.subscription.fragment.SubHistoryFragment;
import com.example.himalayaproject.subscription.fragment.SubRecommendFragment;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

public class BaseSpecialActivity extends AppCompatActivity{
   private ViewPager viewPager ;
    private TabLayout tabLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_special);
        aboutTablayout();

    }

    private void aboutTitle(String title,String playCount,String url ) {
        TextView title1 = (TextView) findViewById(R.id.base_special_title1);
        TextView title2 = (TextView) findViewById(R.id.base_special_title2);
        TextView title3= (TextView) findViewById(R.id.base_special_title3);
        TextView title4 = (TextView) findViewById(R.id.base_special_title4);
        ImageView imageView  = (ImageView) findViewById(R.id.base_special_image);
        title1.setText(title);
        title2.setText("主播: "+title);
        title3.setText("播放: "+playCount+"次");
        title4.setText("状态: 2016-12-09");
        Picasso.with(this).load(url).into(imageView);

    }

    private void aboutTablayout() {
        viewPager = (ViewPager) findViewById(R.id.base_special_viewpager);
        tabLayout = (TabLayout) findViewById(R.id.base_special_tablayout);
        Intent intent = getIntent();
        String albumId = intent.getStringExtra("albumId");
        int  number = intent.getIntExtra("number",0);
        String title = intent.getStringExtra("title");
        String playCounts = intent.getStringExtra("playCounts");
        String imageUrl = intent.getStringExtra("imageUrl");
        aboutTitle(title,playCounts,imageUrl);
        List<String> list = new ArrayList<>();
        list.add("详情");
        list.add("节目("+number+")");
        List<Fragment> fragments = new ArrayList<>();
        SpecialDetailsFragment specialDetailsFragment = SpecialDetailsFragment.newInstance(albumId);
        SpecialProgramFragment specialProgramFragment = SpecialProgramFragment.newInstance(albumId,number);
        fragments.add(specialDetailsFragment);
        fragments.add(specialProgramFragment);
        FindViewpagerAdapter adapter = new FindViewpagerAdapter(getSupportFragmentManager(),list,fragments);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setCurrentItem(1);
    }

}
